package com.tbit.api;

import com.tbit.common.entity.view.Result;
import com.tbit.manager.api.GiftCardUserApi;
import com.tbit.manager.api.dto.GiftCardUserDTO;
import com.tbit.manager.api.vo.UserGiftCardAreaVO;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.business.GiftCardUserService;
import com.tbit.uqbike.service.business.SupportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 区域礼品卡用户余额实现
 *
 * @author ：zhangtianyou
 * @since 2024/11/22
 */
@RestController
@Slf4j
public class GiftCardUserApiImpl implements GiftCardUserApi {

    @Autowired
    private GiftCardUserService giftCardUserService;
    @Autowired
    private SupportService supportService;

    @Override
    public GiftCardUserDTO getGiftCard(Integer accountId, Integer userId) {
        return giftCardUserService.getRechargeMoneyAndGiftMoney(accountId, userId);
    }

    @Override
    public Result<String> rechargeGiftMoney(GiftCardUserDTO giftCardUserDTO) {

        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId(giftCardUserDTO.getLoginUserAccountId());
        loginInfo.setAccountUserId(giftCardUserDTO.getLoginUserAccountUserId());
        loginInfo.setType(giftCardUserDTO.getLoginUserType());
        loginInfo.setName(giftCardUserDTO.getLoginUserName());
        loginInfo.setPhone(giftCardUserDTO.getLoginUserPhone());
        loginInfo.setLoginUserPlatform(giftCardUserDTO.getLoginUserPlatform());
        giftCardUserService.recharge(giftCardUserDTO.getAccountId(), giftCardUserDTO.getUserId(), giftCardUserDTO.getMoney(),
                giftCardUserDTO.getRemark(), loginInfo);
        return Result.success();
    }

    @Override
    public List<UserGiftCardAreaVO> getUserGiftCardRecommendArea(Integer userId) {
        List<com.tbit.uqbike.object.pojo.vo.UserGiftCardAreaVO> list = supportService.getUserGiftCardRecommendArea(userId);
        List<UserGiftCardAreaVO> userGiftCardAreaVOList = new ArrayList<>();
        for (com.tbit.uqbike.object.pojo.vo.UserGiftCardAreaVO userGiftCardAreaVO : list) {
            UserGiftCardAreaVO userGiftCardArea = new UserGiftCardAreaVO();
            BeanUtils.copyProperties(userGiftCardAreaVO, userGiftCardArea);
            userGiftCardAreaVOList.add(userGiftCardArea);
        }
        return userGiftCardAreaVOList;
    }
}
